/*转换为千分位*/
function format (v) {
  // return Number(v).toLocaleString()   /*  一定要是number类型调用toLocaleString()才会有效果*/
  const reg=/\d{1,3}(?=(\d{3})+$)/g
  return `${v}`.replace(reg,'$&,')
}
function wrapperNumber(o,k){
  return o && o[k] ? format(o[k]) : 0
}
/* 给数字后面添加百分号*/
function wrapperPercentage(o,k){
  return o && o[k] ? `${o[k]}%` : '0%'
}
/* 给数字前面添加人民币符号*/
function wrapperMoney(o,k){
  return o && o[k] ? `¥ ${format(o[k])}`: '¥ 0.00'
}

function wrapperArray(o,k){
  return o && o[k] ? o[k]  : []
}

function wrapperOriginalNumber(o,k){
  return o && o[k] ? o[k]  : 0
}

export default {
  inject:['getReportData', 'getMapData', 'getWordCloud'],
  computed:{
    reportData () {
      return this.getReportData()
    },
    salesToday(){
      return wrapperMoney(this.reportData,'salesToday')
    },
    salesGrowthLastDay(){
      return wrapperPercentage(this.reportData,'salesGrowthLastDay')
    },
    salesGrowthLastMonth(){
      return wrapperPercentage(this.reportData,'salesGrowthLastMonth')
    },
    salesLastDay(){
      return wrapperMoney(this.reportData,'salesLastDay')
    },
    orderToday(){
      return wrapperNumber(this.reportData, 'orderToday')
    },
    orderLastDay(){
      return wrapperNumber(this.reportData, 'orderLastDay')
    },
    orderTrend(){
      return wrapperArray(this.reportData, 'orderTrend')
    },
    orderUser(){
      return wrapperNumber(this.reportData, 'orderUser')
    },
    orderUserTrend(){
      return wrapperArray(this.reportData, 'orderUserTrend')
    },
    orderUserTrendAxis(){
      return wrapperArray(this.reportData, 'orderUserTrendAxis')
    },
    returnRate(){
      return wrapperPercentage(this.reportData,'returnRate')
    },
    userToday(){
      return wrapperNumber(this.reportData, 'userToday')
    },
    userTodayNumber(){
      return wrapperOriginalNumber(this.reportData, 'userToday')
    },
    userRank(){
      return wrapperArray(this.reportData, 'userRank')
    },
    userGrowthLastDay(){
      return wrapperPercentage(this.reportData,'userGrowthLastDay')
    },
    userGrowthLastMonth(){
      return wrapperPercentage(this.reportData,'userGrowthLastMonth')
    },
    userLastMonth(){
      return wrapperOriginalNumber(this.reportData,'userLastMonth')
    },
    orderFullYear(){
      return wrapperArray(this.reportData, 'orderFullYear')
    },
    orderFullYearAxis(){
      return wrapperArray(this.reportData, 'orderFullYearAxis')
    },
    orderRank(){
      return wrapperArray(this.reportData, 'orderRank')
    },
    userFullYear(){
      return wrapperArray(this.reportData, 'userFullYear')
    },
    userFullYearAxis(){
      return wrapperArray(this.reportData, 'userFullYearAxis')
    },
    wordCloud(){
      return this.getWordCloud()
    }
  },
  methods:{
    format(v){
      return format(v)
    }
  }
}
